﻿package base.helper;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Hibernate;

public class HibernateHelper
{
	/**
	 * 强制加载lazy=true的属性
	 * @param object 被强制加载的对象
	 * @param lazyPropNames 强制加载的属性
	 */
	public static void initialize(Object object, String... lazyPropNames)
	{
		List<Object> list = new ArrayList<Object>();
		list.add(object);
		
		initialize(list, lazyPropNames);
	}
	
	/**
	 * 强制加载lazy=true的属性
	 * @param list 被强制加载的对象集合
	 * @param lazyPropNames 强制加载的属性
	 */
	public static void initialize(List<Object> list, String... lazyPropNames)
	{
		if(lazyPropNames.length != 0)
		{
			for(Object object : list)
			{
				for(String prop : lazyPropNames)
				{
					Hibernate.initialize(BaseHelper.getPropValue(object, prop));
				}
			}
		}
	}
}
